package com.yzy.fly.type;

import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;
import org.objectweb.asm.Opcodes;

public enum JDKVersionType {
//    int V1_1 = 196653;
//    int V1_2 = 46;
//    int V1_3 = 47;
//    int V1_4 = 48;
//    int V1_5 = 49;
//    int V1_6 = 50;
//    int V1_7 = 51;
//    int V1_8 = 52;
//    int V9 = 53;
//    int V10 = 54;
//    int V11 = 55;
//    int V12 = 56;
//    int V13 = 57;
//    int V14 = 58;
//    int V15 = 59;
//    int V16 = 60;
    V1_1("1.1",Opcodes.V1_1),
    V1_2("1.2",Opcodes.V1_2),
    V1_3("1.3",Opcodes.V1_3),
    V1_4("1.4",Opcodes.V1_4),
    V1_5("1.5",Opcodes.V1_5),
    V1_6("1.6",Opcodes.V1_6),
    V1_7("1.7",Opcodes.V1_7),
    V1_8("1.8",Opcodes.V1_8),
    V9("9",Opcodes.V9),
    V10("10",Opcodes.V10),
    V11("11",Opcodes.V11),
    V12("12",Opcodes.V12),
    V13("13",Opcodes.V13),
    V14("14",Opcodes.V14),
    V15("15",Opcodes.V15),
    V16("16",Opcodes.V16);

    @Setter@Getter
    private String type;
    @Setter@Getter
    private int value;

    JDKVersionType(String type, int value){
        this.type = type;
        this.value = value;
    }

    public static JDKVersionType type(String type){
        if (StringUtils.isBlank(type)) {
            return JDKVersionType.V1_8;
        }
        JDKVersionType jdkVersionType;
        try {
            jdkVersionType = JDKVersionType.valueOf(type);
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
            jdkVersionType = JDKVersionType.V1_8;
        }
        return jdkVersionType;
    }

    public static int value(String type){
        int value = JDKVersionType.V1_8.value;
        if (StringUtils.isBlank(type)) {
            return value;
        }
        JDKVersionType[] values = JDKVersionType.values();
        for (int i = 0; i < values.length; i++) {
            JDKVersionType jdkVersionTypeValue = values[i];
            if (jdkVersionTypeValue.type.equals(type)) {
                value = jdkVersionTypeValue.value;
                break;
            }
        }
        return value;
    }

    public static void main(String[] args) {
        JDKVersionType type = type("V13");
        int i =0;
    }
}
